package top.eggcode.plugins.office.common;

import top.eggcode.common.error.ApplicationException;
import top.eggcode.common.file.FileCompressUtil;
import top.eggcode.common.model.UidGenerator;

/**
 * Title:
 * Description: TODO
 * Date: 2021/6/22 0:40
 *
 * @author JiaQi Ding
 * @version 1.0
 */
public class PathGenerator {

    private final String tempDir;

    public PathGenerator(String tempDir) {
        this.tempDir = tempDir;
    }

    public String getDocument(DocumentCategory category) {
        StringBuilder path = new StringBuilder(this.tempDir);
        // 上级目录
        path.append("document/");
        // 创建该目录
        FileCompressUtil.verifyDir(tempDir);

        // 文件名
        path.append(UidGenerator.apply());
        // 添加文件后缀
        switch (category) {
            case PNG:
                path.append(".png");
                break;
            case WORD2007:
                path.append(".docx");
                break;
            case WORD2003:
                path.append(".doc");
                break;
            case EXCEL2003:
                path.append(".xls");
                break;
            case EXCEL2007:
                path.append(".xlsx");
                break;
            default:
                throw new ApplicationException("未处理的文件类型");
        }
        return path.toString();
    }


}
